package lex.netant;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class Utility {
	public static int antNum = 5;
	public static String url;
	public static String defaultDirectory = "c:\\download";
	public static boolean stop = false;
	public static long nStart[] = { 0l, 0l, 0l, 0l, 0l };
	public static long nStop[] = { 0l, 0l, 0l, 0l, 0l };
	public static long size;
	public static int code;
	public static boolean bStop[] = { false, false, false, false, false };

	public Utility() {
		url = null;
		defaultDirectory = null;
	}

	public static String getFileName() {
		String name;
		int index = url.lastIndexOf("/");
		name = url.substring(index + 1);
		return name;
	}

	public static String getTempFileName() {
		String name;
		int firstindex = url.lastIndexOf("/");
		int lastindex = url.lastIndexOf(".");
		name = url.substring(firstindex + 1, lastindex);
		return name;
	}

	public static void serializeOut() {
		try {
			File tempFile = new File(getTempFileName() + "." + "tmp");
			FileOutputStream file = new FileOutputStream(tempFile);
			ObjectOutputStream serialize = new ObjectOutputStream(file);
			for (int i = 0; i < 5; i++) {
				serialize.writeObject(String.valueOf(nStart[i]));
				serialize.writeObject(String.valueOf(nStop[i]));
			}
			serialize.flush();
			file.close();
			serialize.close();
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}

	public static void deleteTempFile() {
		File tempFile = new File(getTempFileName() + "." + "tmp");
		tempFile.delete();
	}
}
